﻿using Android.App;
using Android.Content;
using Android.OS;
using Android.Runtime;
using Android.Views;
using Android.Widget;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Client.AndroiD
{
    public class MyBroadcastReceiver : BroadcastReceiver
    {
        /// <summary>
        /// 转发广播
        /// </summary>
        bool mIsSend { get; set; }

        string mKeyOfData;

        public MyBroadcastReceiver(bool isSend, string data)
        {
            mIsSend = isSend;
            mKeyOfData = data;
        }

        public override void OnReceive(Context context, Intent intent)
        {
            string data = intent.GetStringExtra(mKeyOfData);
            // TODO Get Barcode Type

            if (data.IsNullOrEmpty() == true)
            {
                return;
            }

            if (mIsSend == true)
            {
                // 转发广播
                // MainActivity.ZhuanFaGuangBo("", "", data); // TODO 兼容 Zebra ????
                MainActivity.RunZhuanFaGuangBo(data);
            }
            else
            {
                // 在 Activity 中显示
                Util.MessagingCenter.Send(this, MainActivity.KEY_RECEIVE, data);
            }
        }

        
    }
}